package com.dongdongshop.service.impl;

import com.dongdongshop.mapper.TbSellerMapper;
import com.dongdongshop.pojo.TbSeller;
import com.dongdongshop.pojo.TbSellerExample;
import com.dongdongshop.service.SellerService;
import com.sun.org.apache.bcel.internal.generic.NEW;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@DubboService
@Service
public class SellerServiceImpl implements SellerService {

    @Autowired
    private TbSellerMapper tbSellerMapper;

    @Override
    public TbSeller selectSellerById(String sellerId) {
        return tbSellerMapper.selectByPrimaryKey(sellerId);
    }

    @Override
    public void insertSeller(TbSeller seller) {
        tbSellerMapper.insertSelective(seller);
    }

    @Override
    public TbSeller getAdminById(String username) {
        return tbSellerMapper.selectByPrimaryKey(username);
    }

    @Override
    public TbSeller getAdminByEmail(String username) {
        TbSellerExample example = new TbSellerExample();
        TbSellerExample.Criteria criteria = example.createCriteria();
        criteria.andLinkmanEmailEqualTo(username);
        List<TbSeller> tbSellers = tbSellerMapper.selectByExample(example);
        return tbSellers.size()>0 ? tbSellers.get(0):null;
    }

    @Override
    public TbSeller getAdminByTel(String username) {
        TbSellerExample example = new TbSellerExample();
        TbSellerExample.Criteria criteria = example.createCriteria();
        criteria.andTelephoneEqualTo(username);
        List<TbSeller> tbSellers = tbSellerMapper.selectByExample(example);
        return tbSellers.size()>0 ? tbSellers.get(0):null;
    }

    @Override
    public List<TbSeller> listSeller() {
        return tbSellerMapper.selectByExample(null);
    }

    @Override
    public void updateStatus(List<String> ids) {
        TbSellerExample example = new TbSellerExample();
        TbSellerExample.Criteria criteria = example.createCriteria();
        criteria.andSellerIdIn(ids);
        TbSeller seller = new TbSeller();
        seller.setStatus("1");
        tbSellerMapper.updateByExampleSelective(seller,example);
    }
}
